<template>
  <div class="container">
    <div class="container-1200">
      <div class="flexWithJusBetween mg-B20">
        <div class="title">企业资料</div>
        
        <!-- <div>
          <el-button type="primary" @click="addCompany">添加企业</el-button>
          <el-button type="primary" @click="editCompany"
            >修改企业信息</el-button
          >
          <el-button type="primary" @click="toProject">查看企业项目</el-button>
          <el-button type="success" @click="submitCompany">企业提交审核</el-button>
        </div> -->
      </div>
      <!-- <div>
        <div style="color: red; margin-left: 20px;">审核状态：{{companyStatusFormate(companyInfo.status)}}</div>
        <div style="color: red; margin-left: 20px;" v-if="companyInfo.memo">驳回说明：{{companyInfo.memo}}</div>
      </div> -->
      <div>
        <el-row class="rowBorder rowTopBorder">
          <el-col :span="4" class="col-flex bg-ccc">企业名称</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30 colRightBorder">{{
            companyInfo.name
          }}</el-col>
          <el-col :span="4" class="col-flex bg-ccc">统一社会信用代码</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30">{{
            companyInfo.code
          }}</el-col>
        </el-row>
        <el-row class="rowBorder">
          <el-col :span="4" class="col-flex bg-ccc">法定代表人</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30 colRightBorder">{{
            companyInfo.legalPerson
          }}</el-col>
          <el-col :span="4" class="col-flex bg-ccc">注册资本(万元)</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30">{{
            companyInfo.capital
          }}</el-col>
        </el-row>
        <el-row class="rowBorder">
          <el-col :span="4" class="col-flex bg-ccc">负责人</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30 colRightBorder">{{
            companyInfo.linkman
          }}</el-col>
          <el-col :span="4" class="col-flex bg-ccc">负责人联系方式</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30">{{
            companyInfo.phone
          }}</el-col>
        </el-row>
        <el-row class="rowBorder">
          <el-col :span="4" class="col-flex bg-ccc">注册地址</el-col>
          <el-col :span="20" class="col-flex colLeftBorder leftAlign-pd30">
            {{ companyInfo.registerAddress }}
          </el-col>
        </el-row>
        <el-row class="rowBorder">
          <el-col :span="4" class="col-flex bg-ccc">办公地址</el-col>
          <el-col :span="20" class="col-flex colLeftBorder leftAlign-pd30">{{
            companyInfo.officeAddress
          }}</el-col>
        </el-row>
        <el-row class="rowBorder">
          <el-col :span="4" class="col-flex bg-ccc">行业类别</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30 colRightBorder">{{
            industryFormate(companyInfo.industry)
          }}</el-col>
          <el-col :span="4" class="col-flex bg-ccc">注册类型</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30">{{
            registrationFormate(companyInfo.registration)
          }}</el-col>
        </el-row>
        <el-row class="rowBorder">
          <el-col :span="4" class="col-flex bg-ccc">纳税类型</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30 colRightBorder">{{
            taxTypeFormate(companyInfo.taxType)
          }}</el-col>
          <el-col :span="4" class="col-flex bg-ccc">所属部门</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30">{{
            officeIdFormate(companyInfo.officeId)
          }}</el-col>
        </el-row>
        <!-- <el-row class="rowBorder">
          <el-col :span="4" class="col-flex bg-ccc">企业状态</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30 colRightBorder">{{
            companyStatusFormate(companyInfo.status)
          }}</el-col>
          <el-col :span="4" class="col-flex bg-ccc">驳回说明</el-col>
          <el-col :span="8" class="col-flex colLeftBorder leftAlign-pd30">{{
            companyInfo.memo
          }}</el-col>
        </el-row> -->
        <el-row class="rowBorder bg-ccc">
          <el-col :span="4" class="">
            <div>
              <div class="textCenter">营业执照</div>
              <div class="textCenter">(点击下载)</div>
            </div></el-col
          >
          <el-col
            :span="20"
            class="col-flex leftAlign-pd30 colLeftBorder leftAlign-pd30 bg-fff"
          >
            <div style="margin:10px">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="companyInfo.meta"
                  placeholder="请上传营业执照"
                  error="请上传营业执照"
                  fit="contain"
                >
                </el-image>
                <div class="flexWithJusCenter">
                   <el-link :href="companyInfo.meta" target="_blank" type="primary" class="link">营业执照</el-link> 
                </div>
              </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import {
  submit as submitCompany,
  find as companyFind,
} from "@/api/adminCompany";
import { list as dictList } from "@/api/dict";
import { list as officeList } from "@/api/sysOffice";
import utils from "@/utils/utils.js";

export default {
  components: {},
  name: "company",
  data() {
    return {
      companyId: "",
      companyInfo: {
        code: "",
        name: "",
        legalPerson: "",
        capital: "",
        linkman: "",
        phone: "",
        registerAddress: "",
        officeAddress: "",
        industry: "",
        registration: "",
        taxType: "",
        status: "",
        memo: "",
        deleted: "",
        officeId: "",
        userId: "",
        meta: "",
        createBy: "",
        modifyBy: "",
      },

      //部门列表
      offices: [],

      //字典数据
      taxTypeDict: [],
      registrationDict: [],
      companyStatusDict: [],
      industryDict: [],

      //获取字典的promise
      taxTypeDictPromise: "",
      registrationDictPromise: "",
      companyStatusDictPromise: "",
      officeListPromise: "",
      industryDictPromise: "",

      
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    if (this.$route.query) {
      this.companyId = this.$route.query.companyId;
      
    }
    this.taxTypeDictPromise = utils.getDictList("tax_type", (res) => {
      this.taxTypeDict = res.data;
    });
    this.registrationDictPromise = utils.getDictList("registration", (res) => {
      this.registrationDict = res.data;
    });
    this.companyStatusDictPromise = utils.getDictList(
      "company_status",
      (res) => {
        this.companyStatusDict = res.data;
      }
    );
    this.industryDictPromise = utils.getDictList("industry", (res) => {
      this.industryDict = res.data;
    });
    this.officeListPromise = this.officeList();
  },

  mounted() {
    Promise.all([
      this.taxTypeDictPromise,
      this.registrationDictPromise,
      this.companyStatusDictPromise,
      this.officeListPromise,
      this.industryDictPromise,
    ]).then((res) => {
      //console.log("字典已经全部加载完成--");
      this.companyFind(this.companyId);
    });
  },

  destroyed() {},

  methods: {
    //获取公司信息
    companyFind(id) {
      companyFind(id).then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyInfo = res.data.company;
          // if (!utils.isNull(this.companyInfo.meta)) {
          //   this.companyInfo.meta = JSON.parse(this.companyInfo.meta);
          // }
        }
        console.log("this.companyInfo--", this.companyInfo);
      });
    },

    officeList() {
      let _this = this;
      let params = new URLSearchParams();
      params.append("menuType", 0);
      return officeList(params)
        .then((response) => {
          console.log("部门信息--", response);
          _this.offices = response.data;
        })
        .catch((error) => {
          console.log("error!!");
        });
    },

    //创建企业
    addCompany() {
      this.$router.push({ path: "/company/add" });
    },

    //修改企业信息
    editCompany() {
      this.$router.push({
        path: "/company/edit",
        query: { companyId: this.companyInfo.id },
      });
    },

    //查看企业项目
    toProject() {
      this.$router.push({
        path: "/project/list",
        query: { companyId: this.companyInfo.id },
      });
    },

    //企业的提交审核
    submitCompany() {
      let params = new URLSearchParams();
      params.append("companyId", this.companyInfo.id);
      submitCompany(params).then((res) => {
        console.log("企业的提交审核--", res);
        if (res.type == "success") {
          this.$message.success("企业信息提交成功");
        }
      });
    },

    //字典信息获取
    getDictList(type, callback, errCallback) {
      let params = new URLSearchParams();
      params.append("dictType", type);
      return dictList(params)
        .then((res) => {
          console.log(type + "字典--", res);
          if (res.type == "success") {
            if (callback) {
              callback(res.data);
            }
          }
        })
        .catch((err) => {
          if (errCallback) {
            errCallback();
          }
        });
    },

    //字典数据格式化
    taxTypeFormate(data) {
      console.log("纳税data--", data);
      return utils.selectDictLabel(this.taxTypeDict, data);
    },

    registrationFormate(data) {
      return utils.selectDictLabel(this.registrationDict, data);
    },

    companyStatusFormate(data) {
      return utils.selectDictLabel(
        this.companyStatusDict,
        "company_status-" + data
      );
    },

    industryFormate(data) {
      console.log("data--", data);
      return utils.selectDictLabel(this.industryDict, data);
    },

    officeIdFormate(data) {
      return utils.selectDictLabel(this.offices, data);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
